﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ARR.Entities.Validation.ComponentModel;
using ARR.Entities.ComponentModel;
using ARR.Entities.Validation.Common;
using ARR.Shared;

namespace ARR.Entities.Validation
{
    [Serializable]
    public class CategoryMatchInputValidations : InputValidationBase
    {
        private CategoryMatch match;

        public CategoryMatchInputValidations(CategoryMatch match)
        {
            this.match = match;
        }

        public override List<ValidationBase> CreateValidations()
        {
            List<ValidationBase> inputValidations = new List<ValidationBase>();


            inputValidations.Add(new CustomValidation("Name", Labels.OriginalCategory, delegate()
                {
                    if (!match.SourceCategoryId.HasValue)
                    {
                        return !string.IsNullOrWhiteSpace(match.Name);
                    }
                    
                    return true;
                }));

            inputValidations.Add(new CustomValidation("SourceCategoryId", Labels.OriginalCategory, delegate()
                {
                    if (string.IsNullOrWhiteSpace(match.Name))
                    {
                        return match.SourceCategoryId.HasValue;
                    }

                    return true;
                }));

            inputValidations.Add(new Required("CategoryId", Labels.Equivalencia));


            return inputValidations;
        }
    }
}
